function WebGLBoardTokens(gl)
{
	var crown = new WebGLCrown(gl);
	var max_models = 6;
	var pieces = new WebGLPieces(gl, max_models, 0.35);
	var tokens = undefined;
	var width = undefined;
	var height = undefined;
	var num_of_pieces = undefined;

	this.update = function(player, game, fsm)
	{
		var hierarkia = game.hierarkia();
		this.tokens = [];
		
		this.width = game.info.width;
		this.height = game.info.height;
		this.num_of_pieces = game.info.pieces;
		
		for(var x = 0; x < this.width; ++x)
		{
			for(var y = 0; y < this.height; ++y)
			{
				var index = x * this.height + y;
				
				var cell = hierarkia.cells[index];
				if (cell != null)
				{
					var token = { color: undefined, crowns: 0, piece: undefined };
					if (cell.side == Side.BLUE) token.color = [0.0, 0.0, 1.0, 1.0];
					else if (cell.side == Side.RED) token.color = [1.0, 0.0, 0.0, 1.0];
					token.piece = cell.value;
					
					if (max_models - token.piece < 0)
					{
						token.crowns = token.piece - max_models;
					}
					else if (this.num_of_pieces == token.piece)
					{
						token.crowns += 1;
					}
					
					this.tokens[index] = token; 
				}
			}
		}
	}
	
	this.draw = function(projection, view, mouseover)
	{		
		for(var x = 0; x < this.width; ++x)
		{
			for(var y = 0; y < this.height; ++y)
			{
				var index = x + y * this.width;
				
				var token = this.tokens[index];
				if (token == null) continue;
				
				var piece = pieces.getPiece(token.piece);
				
				var translatePiece = 
				[
					1,	0,	0,	x - this.width / 2.0 + 0.5,
					0,	1,	0,	0.05,
					0,	0,	1,	y - this.height / 2.0 + 0.5,
					0,	0,	0,	1
				];
				
				var translateCrown = 
				[
					1, 0, 0, x - this.width / 2.0 + 0.5,
					0, 1, 0, piece.getHeight() + 0.15,
					0, 0, 1, y - this.height / 2.0 + 0.5,
					0, 0, 0, 1
				];
							
				var scaleCrown = 
				[
					0.1,  	0.0,	0.0,	0.0,
					0.0,  	0.1,	0.0,	0.0,
					0.0,  	0.0,	0.1,	0.0,
					0.0,  	0.0,	0.0,	1.0
				];
				
				pieces.draw(token.piece - 1, projection, view, translatePiece, token.color);
			
				for (var i = 0; i < token.crowns; ++i)
				{
					translateCrown[7] = piece.getHeight() + 0.15 + i;
					crown.draw(projection, view, mmul(translateCrown, scaleCrown, 4), token.color);
				}
			}
		}
	}
}
